import operate from '@dfeidao/atom-nodejs/db/operate';
import log from '@dfeidao/atom-nodejs/logger/log';
import { IncomingHttpHeaders } from 'http';
import { systemid } from '../atom/config';

interface Message {
	params: {
		student_no: string, // 学生编号
		faceid: string, // 人脸id
		productid: string // 产品ID
	};
}

interface IWebResult {
	data: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string;
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	log('Service begin path:app-check-status/s002,action_id:' + action_id);
	const { exec, insert, update } = operate(action_id, session_id, systemid);
	// 插入数据保存到<人脸图库>
	insert('face_gallery', message.params);
	// 修改依据”学生编号“修改<学生>“是否录入人脸”为“1是”
	update('student', { productid: message.params.productid, student_no: message.params.student_no }, { whether_enter_face: '1' });
	const res = await exec();
	log('Service end path:app-check-status/s002,action_id:' + action_id);
	return {
		data: res
	};
}
